rows = [
    {'address': '5412 N CLARK', 'date': '07/01/2012'},
    {'address': '5148 N CLARK', 'date': '07/04/2012'},
    {'address': '5800 E 58TH', 'date': '07/02/2012'},
    {'address': '2122 N CLARK', 'date': '07/03/2012'},
    {'address': '5645 N RAVENSWOOD', 'date': '07/02/2012'},
    {'address': '1060 W ADDISON', 'date': '07/02/2012'},
    {'address': '4801 N BROADWAY', 'date': '07/01/2012'},
    {'address': '1039 W GRANVILLE', 'date': '07/04/2012'},
]

if __name__ == '__main__':
    # 旧方法
    rows_date = sorted(set([x['date'] for x in rows]))
    for date0 in rows_date:
        print(date0)
        for i in rows:
            if i['date'] == date0:
                print(' ', i)


    # 新方法
    print('*' * 100)
    from operator import itemgetter
    from itertools import groupby

    rows.sort(key=itemgetter('date'))
    for date, items in groupby(rows, key=itemgetter('date')):
        print(date)
        for i in items:
            print('  ', i)

    # 新方法2
    # 将数据分组到一个大的数据结构
    print('*' * 100)
    from collections import defaultdict
    rows_by_date = defaultdict(list)
    for row in rows:
        rows_by_date[row['date']].append(row)
    print(rows_by_date)
    for r in rows_by_date['07/01/2012']:
        print(r)